<template>
  <div class="GCompanyCheckDetail" :loading="loading">
    <zyInfoPanel title="基本信息" :showUnfoldButton="false" class="baseInfo">
      <div class="baseBox">
        <zy-modal-info :model-info="baseInfo" cell-num="4"></zy-modal-info>
      </div>
    </zyInfoPanel>
    <zyInfoPanel title="业务信息" :showUnfoldButton="false" class="baseInfo">
      <div class="bussinessContainer">
        <div class="line-box">
          <div class="line-item ">
            <div class="line-item-name">负责人姓名：</div>
            <div class="line-item-val">{{control_man}}</div>
          </div>
          <div class="line-item">
            <div class="line-item-name">负责人联系方式：</div>
            <div class="line-item-val">{{control_phone}}</div>
          </div>
        </div>
        <div class="area-cont">
          <div class="area-item-name">物流线路：</div>
          <div class="area-box" :class="i==0?'noPadd':''" v-for="(list,i) in circuit_list" :key="i">
            <div class="area-item" :class="j==list.length-1?'last-area-item':''" v-for="(item,j) in list" :key="j">
              <el-cascader v-model="item.id" :options="arrive_region" filterable disabled
                           :props="{ checkStrictly: true,value:'value',label:'label',children:'children' }"
                           clearable>
              </el-cascader>
            </div>
          </div>
        </div>
      </div>
    </zyInfoPanel>
    <zyInfoPanel title="附件信息" :showUnfoldButton="false" class="baseInfo">
      <div class="cooperativeImgContent">
        <div class="imgItem">
          <div class="itemTitle">营业执照（副本）</div>
          <div class="itemContent">
            <el-upload
                class="upload-demo"
                drag
                action=""
                :httpRequest="uploadFile"
                :data="{type: 'license_img'}"
                accept=".jpg,.jpeg,.png,.bmp,.wbmp,.JPG,.JPEG,.PNG,.BMP,.WBMP"
                :show-file-list="false" disabled
            >
              <zy-image v-model="license_img" :readonly="type=='detail'" v-if="license_img"></zy-image>
              <i class="el-icon-upload"></i>
              <div class="el-upload__text">
                请上传营业执照（副本）
              </div>
            </el-upload>
          </div>
        </div>
        <div class="imgItem card">
          <div class="itemTitle">法人身份证</div>
          <div class="itemContent">
            <el-upload
                class="upload-demo"
                drag
                action=""
                :httpRequest="uploadFile"
                :data="{type: 'legal_card_pros'}"
                accept=".jpg,.jpeg,.png,.bmp,.wbmp,.JPG,.JPEG,.PNG,.BMP,.WBMP"
                :show-file-list="false" disabled
            >
              <zy-image :readonly="type=='detail'" v-model="legal_card_pros" v-if="legal_card_pros"></zy-image>
              <i class="el-icon-upload"></i>
              <div class="el-upload__text">
                请上传身份证正面
              </div>
            </el-upload>
            <el-upload
                class="upload-demo"
                drag
                action=""
                :httpRequest="uploadFile"
                :data="{type: 'legal_card_cons'}"
                accept=".jpg,.jpeg,.png,.bmp,.wbmp,.JPG,.JPEG,.PNG,.BMP,.WBMP"
                :show-file-list="false" disabled
            >
              <zy-image v-model="legal_card_cons" :readonly="type=='detail'" v-if="legal_card_cons"></zy-image>
              <i class="el-icon-upload"></i>
              <div class="el-upload__text">
                请上传身份证反面
              </div>
            </el-upload>
          </div>
        </div>
      </div>
    </zyInfoPanel>
    <zyInfoPanel title="监管设置" :showUnfoldButton="false" class="baseInfo">
      <div class="baseBox">
        <zy-modal-info :model-info="setInfoDesc" cell-num="4"></zy-modal-info>
      </div>
    </zyInfoPanel>
    <zyInfoPanel title="信息审核" :showUnfoldButton="false" class="baseInfo" v-if="type==='check'">
      <div class="bussinessContainer">
        <div class="check-box">
          <div class="check-box-name">审核备注：</div>
          <zy-input class="check-box-textarea" type="textarea" placeholder="请输入审核备注" v-model="remark"></zy-input>
        </div>
      </div>
      <div class="btn-box">
        <zy-button @click="submit('2')" type="danger">拒绝</zy-button>
        <zy-button @click="back">取消</zy-button>
        <zy-button @click="submit('1')" type="primary">通过</zy-button>
      </div>
    </zyInfoPanel>
    <zy-info-panel title="操作日志" :showUnfoldButton="false" class="baseInfo">
      <zy-logs logsTitle="" :logs="logList"></zy-logs>
    </zy-info-panel>
  </div>
</template>

<script>
	import {mapGetters} from "vuex";

	export default {
		name: "GCompanyCheckDetail",
		props: {},
		data() {
			return {
				loading: false,
				apply_id: '',
				remark: '',
				baseInfo: [
					{
						title: '企业类型',
						name: 'type',
						type: 'select',
						value: '',
						optionList: [
							{label: '物流', value: 0},
							{label: '快递', value: 1},
							{label: '分拣中心', value: 2},
						],
						titleClass: 'required'
					},
					{
						title: '企业名称',
						name: 'company_name',
						type: 'input',
						value: '',
						titleClass: 'required'
					},
					{
						title: '统一社会信用代码',
						name: 'organization_code',
						type: 'input',
						value: '',
						titleClass: 'required'
					},
					{
						title: '法人姓名',
						name: 'legal_person',
						type: 'input',
						value: '',
						titleClass: 'required'
					},
					{
						title: '法人联系方式',
						name: 'legal_phone',
						type: 'input',
						value: '',
						titleClass: 'required'
					},
					{
						title: '法人身份证',
						name: 'legal_card_no',
						type: 'input',
						value: '',
						titleClass: 'required'
					},
					{
						title: '经营期限',
						name: 'buiss_time',
						type: 'date',
						value: [],
						titleClass: 'required'
					},
					{
						title: '经营地址',
						name: 'company_address',
						type: 'input',
						value: '',
						titleClass: 'required'
					},
					{
						title: '地址定位',
						name: 'location',
						btnName: '定位',
						type: 'location',
						value: {},
						titleClass: 'required'
					}
				],
				setInfoDesc: [
					{
						title: '    监管辖区',
						name: 'regulated_name',
						type: 'select',
						value: '',
						optionList: [],
						readonly: true
					}, {
						title: '监管民警',
						name: 'plc_name',
						type: 'select',
						value: '',
						optionList: [],
						readonly: true
					}],
				arrive_region: [],
				circuit_list: [],
				license_img: '',
				legal_card_pros: '',
				legal_card_cons: '',
				type: '',
				control_man: '',
				control_phone: '',
				fixed_address: '',
				lng: '',
				lat: '',
				logList: [],
				pagination: {
					page_start: 1, //搜索开始页码
					current_page: 1, //当前页码
					page_count: 0, //总页数
					page_size: 10, //每页数量
					total_count: 0 //总数量
				}
			};
		},
		computed: {
			...mapGetters(['getAreaList'])
		},
		watch: {},
		components: {},
		methods: {
			getLogList() {
				this.$getLogs({operation_position: `GCompanyDetail_${this.apply_id}`}).then(res => {
					this.logList = res || [];
				})
			},
			handlerCas(type, index) {
				if (type == '0') {
					this.circuit_list[index].push({id: []})
				} else {
					this.circuit_list[index].splice(-1)
				}
			},
			addItem() {
				this.circuit_list.push([{id: [18, 224, 2063]}, {id: []}])
			},
			getRegionList() {
				if (this.getAreaList.length) {
					this.arrive_region = this.getAreaList;
				} else {
					this.$axios.post(this.$api.arriveRegionList, {}).then(res => {
						let {code, msg, data} = res;
						if (code == 200) {
							this.arrive_region = data;
							this.changeState({areaList: data})
						} else {
							this.$message.error(msg);
						}
					}).catch(ret => {
						console.log(ret)
						this.$message.error(ret.msg || '服务繁忙，请稍后再试');
					});
				}
			},
			//获取详情
			getData() {
				this.loading = true;
				this.$axios.post(this.$api.g_companyApplyDetail, {apply_id: this.apply_id, company_type: 1}).then(res => {
					let {code, msg, data} = res;
					this.loading = false
					if (code === 200) {
						this.baseInfo = this.baseInfo.filter(item => {
							item.readonly = true;
							item.titleClass = ''
							for (let key in data) {
								if (item.name == 'type') {
									item.value = ['物流', '快递', '分拣中心'][data[item.name]]
								} else if (item.name == 'buiss_time') {
									item.value = data.buiss_time_s + ' 至 ' + data.buiss_time_e
								} else if (item.name === 'location') {
									item.readonly = false;
									item.btnName = '查看'
									item.value['address'] = data.fixed_address || ''
								} else if (item.name === key) {
									item.value = data[item.name];
								}
							}
							return item
						});
						this.setInfoDesc = this.setInfoDesc.filter(item => {
							item.readonly = true;
							for (let key in data) {
								if (item.name == 'plc_name') {
									let arr = [];
									data.company_police_list.forEach(it => {
										arr.push(it.sname)
									})
									item.value = arr.join();
								} else if (item.name === key) {
									item.value = data[item.name];
								}
							}
							return item
						})
						if (data.detail_tansline.length > 0) {
							this.circuit_list = data.detail_tansline.filter(item => {
								for (let val of item) {
									val.id = [val.p_region_id, val.r_region_id, val.region_id]
								}
								return item;
							})
						}
						this.license_img = data.license_img;
						this.legal_card_pros = data.legal_card_pros;
						this.legal_card_cons = data.legal_card_cons;
						this.control_man = data.control_man;
						this.control_phone = data.control_phone;
						this.fixed_address = data.fixed_address;
						this.lng = data.lng;
						this.lat = data.lat;
					} else {
						this.$message.error(msg);
					}
				}).catch(ret => {
					console.log(ret)
					this.loading = false
					this.$message.error(ret.msg || '服务繁忙，请稍后再试');
				})
			},
			uploadFile(params) {
				let type = params.data.type;
				this.$axios.post(this.$api.uploadFile, {
					isFile: true,
					file: params.file,
					operator: 'goods',
				}).then(res => {
					if (res.code == 200) {
						this.$message.success(res.msg);
						this[type] = res.data.url;
					} else {
						this.$message.error(res.msg);
					}
				})
			},
			submit(status) {
				if (status == '2' && !this.remark) {
					return this.$message.error('请输入审核备注')
				}
				let postData = {
					apply_id: this.apply_id,
					status: status,
					remark: this.remark || '',
					company_type: 1
				};
				this.$confirm(`是否${status == '1' ? '审核通过' : '审核不通过'}该企业?`, "提示", {
					confirmButtonText: "确定",
					cancelButtonText: "取消",
					type: "warning",
					customClass: 'message',
					closeOnClickModal: false
				}).then(() => {
					this.$axios.post(this.$api.g_companyCheck, {
						...postData
					}).then(res => {
						let {code, msg, data} = res;
						this.loading = false;
						if (code == 200) {
							this.$message.success('提交成功!');
							if (this.type == 'check') {
								this.$saveLogs({
									operation_position: `GCompanyDetail_${this.apply_id}`,
									operation_content: `${status == '1' ? '审核通过' : '审核不通过'}${this.remark ? ',审核原因为' + this.remark : ''}`
								});
							}
							this.back();
						} else {
							this.$message.error(msg);
						}
					}).catch(ret => {
						this.$message.error(ret.msg || '服务繁忙，请稍后再试');
					});
				}).catch(() => {
					this.$message("已取消");
				});
			},
			back() {
				this.$blackRoute({path: '/company_check', that: this})
			},
			getPoliceData() {
				this.$axios.post(this.$api.g_listContactPolice, {
					pagination: {
						page_start: 1,
						page_size: 9999
					}
				}).then(res => {
					let {code, msg, data} = res;
					if (code == 200) {
						this.setFilterData({
							plc_name: data.list.filter(item => {
								item.value = item.id;
								item.label = item.name
								return item;
							}),
						}, ['plc_name']);
					} else {
						this.$message.error(msg);
					}
				}).catch(ret => {
					console.log(ret)
					this.$message.error(ret.msg || '服务繁忙，请稍后再试');
				});
			},
			getRegulatedData() {
				this.$axios.post(this.$api.g_regulatedList, {
					pagination: {
						page_start: 1,
						page_size: 9999
					}
				}).then(res => {
					let {code, msg, data} = res;
					if (code == 200) {
						this.setFilterData({
							regulated_name: data.list.filter(item => {
								item.value = item.regulated_id;
								item.label = item.regulated_name
								return item;
							}),
						}, ['regulated_name']);
					} else {
						this.$message.error(msg);
					}
				}).catch(ret => {
					console.log(ret)
					this.$message.error(ret.msg || '服务繁忙，请稍后再试');
				});
			},
			setFilterData(val, nameList) {
				for (let item of this.setInfoDesc) {
					if (nameList.indexOf(item.name) !== -1) {
						item.optionList = val[item.name]
					}
				}
			},
		},
		mounted() {
			this.apply_id = this.$route.query.apply_id;
			this.type = this.$route.query.type;
			this.getRegionList();
			this.getPoliceData();
			this.getRegulatedData();
			if (this.type != 'add') {
				this.getData();
			}
			this.getLogList();
		},
		created() {
		}
	}
</script>

<style scoped lang="less" src="@/style/government/company/companyCheckDetail/index.less">

</style>
